package com.isscollege.model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;



public class myJdbc {
	
	private Connection conn=null;
	private Statement sm=null;
	private ResultSet rs=null;
	
	@Test
	public void test(String id) throws ClassNotFoundException, SQLException{
		String url="jdbc:mysql://127.0.0.1:3306/njyd?"
				+ "useUnicode=true&amp;characterEncoding=utf-8";
		Class.forName("com.mysql.jdbc.Driver");
		String user="root";
		String pwd="518wsgtc";
		conn=DriverManager.getConnection(url, user, pwd);
		sm=conn.createStatement();
//		String sql=" SELECT a.id,a.test "
//+" from test a";
		StringBuilder sb=new StringBuilder(" SELECT a.id,a.test "
				+" from test a where 1=1 ");
		sb.append(" and a.id="+id);
		System.out.println("sql="+sb.toString());
		rs=sm.executeQuery(sb.toString());
		List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
		while(rs.next()){
			
			int a=rs.getInt("id");
			String b=rs.getString("test");
			Map<String,Object> map1=new HashMap<String,Object>();
			map1.put("id", a);
			map1.put("test", b);
			list.add(map1);
			System.out.println("id="+a+",test="+b);
		}
		//一种是json,一种是xml
		System.out.println(list);
		rs.close();
		sm.close();
		conn.close();
	}
	
	
	

}
